package com.jsf.study;

import java.io.Serializable;
import java.util.List;

import javax.faces.application.Application;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@ManagedBean
@SessionScoped
public class JsfButtonMB implements Serializable{
	
	
	/**
	 * 
	 */
	private static final Log log = LogFactory.getLog(JsfButtonMB.class);
	
	private static final long serialVersionUID = 7108555978621806139L;
	private int numControls;
	private HtmlPanelGrid controlPanel = new HtmlPanelGrid();

	public void addControls(ActionEvent actionEvent) {
		log.info("addControls invoked");
		Application application = FacesContext.getCurrentInstance().getApplication();
		List children = controlPanel.getChildren();
		children.clear();
		for (int count = 0; count < numControls; count++) {
			HtmlOutputText output = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
			output.setValue(" " + count + " ");
			output.setStyle("color: blue");
			children.add(output);
		}
		log.debug("addControls invoked");
	}

	public int getNumControls() {
		return numControls;
	}

	public void setNumControls(int numControls) {
		this.numControls = numControls;
	}

	public HtmlPanelGrid getControlPanel() {
		return controlPanel;
	}

	public void setControlPanel(HtmlPanelGrid controlPanel) {
		this.controlPanel = controlPanel;
	}
}
